<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0"
    />
    <title>Document</title>
  </head>
  <body>
    <script>
      let inherits = (function () {
        function A() {}
        return function (target, origin) {
          A.prototype = origin.prototype; //  A.prototype 只是一个 堆地址 所一多次掉用inherits 没问题
          // a.__proto__  指向是 origin.prototype 的 内存地址
          // a.__proto__  = origin.prototype; // 这样写更好理解
          target.prototype = new A(); // 增加了一层;
          target.prototype.constructor = target;
          target.prototype.super = origin;
        };
      })();
      function A1() {
        this.a = 1;
      }
      A1.prototype.a = 11;
      function A2() {
        this.a = 2;
      }
      A2.prototype.a = 22;
      function B1() {
        console.log(this.a, 'B1');
      }

      function B2() {
        console.log(this.a, 'B2');
      }

      inherits(B1, A1);
      inherits(B2, A2);
      let b1 = new B1();
      let b2 = new B2();
    </script>
  </body>
</html>
